package org.tloss.web.editor.form.editors.command;

import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
import org.tloss.web.editor.model.command.Reply;

public class ReplyProperty implements IPropertySource {
	public static final String RETURN_CASE_PRO = "RETURN_CASE_PRO";
	public static final String VIEW_NAME_PRO = "VIEW_NAME_PRO";
	private Reply command;
	private IResourceChangeListener listener;
	private IPropertyDescriptor[] descriptors;

	public ReplyProperty() {
		descriptors = new IPropertyDescriptor[2];
		descriptors[0] = new TextPropertyDescriptor(RETURN_CASE_PRO,
				"Return case");
		descriptors[1] = new TextPropertyDescriptor(VIEW_NAME_PRO, "View Name");
	}

	public Reply getCommand() {
		return command;
	}

	public void setCommand(Reply command) {
		this.command = command;
	}

	public IResourceChangeListener getListener() {
		return listener;
	}

	public void setListener(IResourceChangeListener listener) {
		this.listener = listener;
	}

	@Override
	public Object getEditableValue() {
		return this;
	}

	@Override
	public IPropertyDescriptor[] getPropertyDescriptors() {
		return descriptors;
	}

	@Override
	public Object getPropertyValue(Object arg0) {
		if (RETURN_CASE_PRO.equals(arg0)) {
			return command.getReturnCase() != null ? command.getReturnCase()
					: "";
		}
		if (VIEW_NAME_PRO.equals(arg0)) {
			return command.getViewName() != null ? command.getViewName() : "";
		}
		return "";
	}

	@Override
	public boolean isPropertySet(Object arg0) {
		return false;
	}

	@Override
	public void resetPropertyValue(Object arg0) {

	}

	@Override
	public void setPropertyValue(Object arg0, Object arg1) {
		if (RETURN_CASE_PRO.equals(arg0)) {
			command.setReturnCase((String) arg1);
			if (listener != null)
				listener.resourceChanged(null);
		}
		if (VIEW_NAME_PRO.equals(arg0)) {
			command.setViewName((String) arg1);
			if (listener != null)
				listener.resourceChanged(null);
		}
	}
}
